package com.wj;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

public class umbrellaGenerate {
    public static String outputDir = "D:/Java_Project/umbrella-java";//输出的文件夹位置
    public static String packageParent = "com.wj";//父包名
    public static String url = "jdbc:mysql://120.24.182.34:4417/umbrella";

    public static void main(String[] args) {
        FastAutoGenerator.create(url, "root", "963.")
                //全局配置(GlobalConfig)
                .globalConfig(builder -> {
                    builder
//                            .fileOverride()//是否覆盖
                            .disableOpenDir()
                            .outputDir(outputDir + "/src/main/java")
                            .author("wj")
//                .enableSwagger()
                            .dateType(DateType.TIME_PACK)
                            .commentDate("yyyy-MM-dd");
                })
                //包配置
                .packageConfig(builder -> {
                    builder.parent(packageParent)
//                          .moduleName("sys")
                            .entity("pojo")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("dao")
                            .xml("mapper.xml")
                            .controller("controller")
//                          .other("other")
                            .pathInfo(
                                    Collections.singletonMap(
                                            OutputFile.mapperXml, outputDir + "/src/main/resources/mapper"
                                    )
                            );
                })
                //策略配置
                .strategyConfig(builder -> {
                    builder.addTablePrefix("t_", "c_","tb_")// 设置过滤表前缀
                            .enableCapitalMode()//开启大写命名
                            .entityBuilder()
                            .enableLombok()
                            .enableChainModel()
                            .enableTableFieldAnnotation()
                            .mapperBuilder()
                            .enableBaseResultMap()
                            .enableBaseColumnList()
//                            .convertMapperFileName(mapperName->{
//                                return mapperName+"Dao";
//                            })//修改dao的后缀为Dao
                            .serviceBuilder();
                })
//                .injectionConfig(builder -> {
//                    builder.beforeOutputFile((v1,v2)->{
//                        System.out.println(v1.getMapperName());
//                    });
//                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
